﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using NCT.Framework;

using VISS.Web.Frontend;
using VISS.API.Users;

namespace NCT.Web.Frontend.Modules.User.Profile {

    public partial class CropAvatarPage : System.Web.UI.Page {

        protected void Page_Load(object sender, EventArgs e) {
            UserContext userContext = LoginFactory.GetCurrentUser();
            if (userContext == null) {
                Response.Clear();
                Response.Write("<script type='text/javascript'>");
                Response.Write("window.opener.CropAvatarPopupComplete('-1');window.close();");
                Response.Write("</script>");
                return;
            }
            long imageID = ConvertUtils.ToLong(Request.QueryString["iid"]);

            UserImageEnt imageItem = StructureMapFactory.GetInstance<IUserImage>().GetByUserKeyAndID(userContext.UserKey, imageID);

            if (imageItem == null) {
                Response.Clear();
                Response.Write("<script type='text/javascript'>");
                Response.Write("window.opener.CropAvatarPopupComplete('-2');window.close();");
                Response.Write("</script>");
                return;
            }

            idCropAvatarPopup.SelectedImage = imageItem;
        }
    }
}
